package com.test;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

/**
 * 任务:根据sex的不同,List截取不同的数据,男的要名字,女的要height
 */
public class StreamTest3 {
    public static void main(String[] args) {
        Student stuA = new Student(1, "A", "M", 184);
        Student stuB = new Student(2, "B", "G", 163);
        Student stuC = new Student(3, "C", "M", 175);
        Student stuD = new Student(4, "D", "G", 158);
        Student stuE = new Student(5, "E", "M", 170);
        List<Student> list = new ArrayList();
        list.add(stuA);
        list.add(stuB);
        list.add(stuC);
        list.add(stuD);
        list.add(stuE);

        List<Model3> list2 = new ArrayList();
        list.stream().filter(student->"M".equals(student.getSex())).forEach(student->{
            Model3 model3 = new Model3();
            model3.setData(student.getName());
            list2.add(model3);
        });
        list.stream().filter(student->"G".equals(student.getSex())).forEach(student->{
            Model3 model3 = new Model3();
            model3.setData(""+student.getHeight());
            list2.add(model3);
        });

        System.out.println("list2 = " + list2);
    }
}

@Data
@NoArgsConstructor
@AllArgsConstructor
class Model3{
    private String sex;
    private String data;
}
